/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package justdoit.view;

import java.awt.Component;
import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.TableCellEditor;

/**
 *
 * @author shadone
 */
public class ProgressBarEditor extends AbstractCellEditor implements TableCellEditor {

    private ProgressBarRenderer renderer = new ProgressBarRenderer();

    public ProgressBarEditor() {
        renderer.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                if (!renderer.getValueIsAdjusting()) {
                    stopCellEditing();
                }
            }
        });
    }

    public Object getCellEditorValue() {
        return new Integer(renderer.getValue());
    }

    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        int val = ((Integer) value).intValue();
        renderer.setValue(val);
        return renderer;
    }
}
